<?php
/**
 * Created by PhpStorm.
 * User: ai
 * Date: 2018/1/10
 * Time: 9:46
 */
use backend\assets\JcarouselAsset;
use yii\helpers\Html;

$this->params['breadcrumbs'][] = ['label' => '上传案卷', 'url' => ['/yue-juan/index'], 'target' => '_blank'];
$this->params['breadcrumbs'][] = ['label' => '我的案卷', 'url' => ['/yue-juan/my-upload']];
$this->params['breadcrumbs'][] = ['label' => $searchModel->title, 'url' => ['/yue-juan/scan-view', 'title' => $searchModel->title]];
$this->title = $searchModel->title . '-智能阅卷 让阅卷更轻松';
/* @var $this yii\web\View */

//$this->registerJsFile('@bower/jquery.easing/js/jquery.easing.compatibility.js', ['depends' => backend\assets\AppAsset::className()]);
JcarouselAsset::register($this);
$this->registerJsFile('@web/js/jcarousel.basic.js', ['depends' => JcarouselAsset::className()]);
$this->registerCssFile('@web/css/jcarousel.basic.css', ['depends' => JcarouselAsset::className()]);
$js = <<<JS
$(function() {    
    // $('.jcarousel').jcarousel({           
    //     // Configuration goes here
    // });
    
    // $(".item-li").width($(window).width())
    //
    // $(".jcarousel-pagination").click(function() {
    //   $(".item-li").width($(window).width())
    // })
    
    $(".jcarousel-pagination").html('分页');
    
});
JS;
$this->registerJs($js);
$this->registerCss('

');

echo "<input type='hidden' value='" . implode(',', $arr_win_result) . "' id='win'/>";

$get = Yii::$app->request->get();
$ocr_string = $get['GeneralocrSearch']['ocr_string'];
?>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-offset-0 col-sm-6 col-md-6 col-lg-6">
            <?php echo $this->render('_search', ['model' => $searchModel, 'dataProvider' => $dataProvider, 'ocr_string' => $ocr_string, 'count' => count($arr_win_result)]); ?>
        </div>

    </div>
    <div class="row">
        <div class="col-sm-12 col-md-12 col-lg-12">
            <div class="wrapper">
                <div class="jcarousel-wrapper">

                    <div class="row">
                        <div class="col-sm-12 col-md-12 col-lg-12">
                            <!-- Pagination -->
                            <p class="jcarousel-pagination" style="">
                                <!-- Pagination items will be generated in here -->
                            </p>
                        </div>

                    </div>

                    <div class="row">
                        <div class="col-sm-offset-3 col-sm-6 col-md-6 col-lg-6">
                            <!-- Prev/next controls -->
                            <div class="pagination">
                                <a href="#" class="jcarousel-control-prev"
                                   onclick="">&lsaquo; 上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <a href="#" class="jcarousel-control-next"
                                   onclick="">下一页 &rsaquo;</a>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-sm-12 col-md-12 col-lg-12">

                            <div class="jcarousel">
                                <ul>
                                    <?php


                                    $data = $dataProvider->getModels();
                                    if (is_array($data) && count($data) > 0) {
                                        foreach ($data as $item) {
                                            echo '<li class="item-li"><div class="row"><div class="col-sm-6 col-md-6 col-lg-6"><img id="' . $item->id . '" onclick="$(\'#imgShow\').attr(\'src\',this.src)" data-toggle="modal" data-target="#myModal" src="/' . addslashes($item->path) . '" height="" width="90%"/></div>';
                                            echo '<div class="col-sm-6 col-md-6 col-lg-6">' . $item->filename;
                                            try {
                                                $arr_ocr = json_decode($item->ocr_ret);
                                                if (is_array($arr_ocr->items) && count($arr_ocr->items) > 0) {
                                                    echo '<table class="table table-condensed"><tr><th>编号</th><th>识别结果</th></tr>';
                                                    foreach ($arr_ocr->items as $key => $item) {
                                                        $key++;
                                                        if ($ocr_string) {
                                                            echo "<tr><td>$key</td><td>" . preg_replace('/' . $ocr_string . '/', "<label class='text-danger'><h3>" . $ocr_string . "</h3></label>", $item->itemstring) . "</td></tr>";
                                                        } else {
                                                            echo "<tr><td>$key</td><td>" . $item->itemstring . "</td></tr>";
                                                        }
                                                    }
                                                    echo '</table></div></div></li>';
                                                }
                                            } catch (\yii\base\ErrorException $e) {
                                                echo "no data";
                                            }

                                        }
                                    } ?>

                                </ul>
                            </div>

                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-6 col-md-6 col-lg-6">
            <h1>以上为检索结果</h1>
        </div>
    </div>
</div>


<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">原图</h4>
            </div>
            <div class="modal-body">
                <img src="" class="" id="imgShow" width="100%"/>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>